package org.deltaset.meta.internal;

import java.lang.annotation.Annotation;
import java.util.Date;
import java.util.List;
import java.util.Map;
import org.deltaset.meta.MetaField;
import org.deltaset.meta.internal.mockmeta.persistence.Enumerated;
import org.deltaset.meta.internal.mockmeta.persistence.OneToMany;
import org.deltaset.meta.internal.mockmeta.persistence.Temporal;
import org.deltaset.meta.internal.testvisit.Animal;
import org.deltaset.meta.internal.testvisit.Common;
import org.deltaset.meta.internal.testvisit.EmbeddedFile;
import org.deltaset.meta.internal.testvisit.NameTitle;
import static org.junit.Assert.*;

/**
 *
 * @author dmakariev
 */
public final class PersonHelper {

    private PersonHelper() {
    }
    
    
    
    public static void assertFormFields(final List<MetaField> formMetaFields) {

        //final List<MetaField> formMetaFields = metaHandler.getFormFields();
        assertEquals("formMetaFields.size ", 9, formMetaFields.size());

        {
            final MetaField metaField = formMetaFields.get(0);

            final String propertyLabelKey = metaField.getPropertyLabelKey();
            assertEquals("metaField getPropertyLabelKey() ", "title", propertyLabelKey);

            final String propertyName = metaField.getPropertyName();
            assertEquals("metaField getPropertyName() ", "title", propertyName);

            final String propertyType = metaField.getPropertyType();
            assertEquals("metaField getPropertyType() ", "enum", propertyType);

            final Class originalType = metaField.getOriginalType();
            assertEquals("metaField getOriginalType() ", NameTitle.class, originalType);

            final Class genericType = metaField.getGenericType();
            assertEquals("metaField getGenericType() ", null, genericType);

            final Annotation[] annotations = metaField.getOriginalAnnotations();                    
            assertEquals("metaField getOriginalAnnotations().length ", 1 , annotations.length);
            
            final Annotation a0 = annotations[0];
            assertEquals("metaField a0.annotationType() ", Enumerated.class , a0.annotationType());

            final Map<String, String> params = metaField.getParams();
            assertEquals("metaField getParams().size() ", 0, params.size());
        }
        
        {
            final MetaField metaField = formMetaFields.get(1);

            final String propertyLabelKey = metaField.getPropertyLabelKey();
            assertEquals("metaField getPropertyLabelKey() ", "firstName", propertyLabelKey);

            final String propertyName = metaField.getPropertyName();
            assertEquals("metaField getPropertyName() ", "firstName", propertyName);

            final String propertyType = metaField.getPropertyType();
            assertEquals("metaField getPropertyType() ", "string", propertyType);

            final Class originalType = metaField.getOriginalType();
            assertEquals("metaField getOriginalType() ", String.class, originalType);

            final Class genericType = metaField.getGenericType();
            assertEquals("metaField getGenericType() ", null, genericType);

            final Annotation[] annotations = metaField.getOriginalAnnotations();                    
            assertEquals("metaField getOriginalAnnotations().length ", 0 , annotations.length);            

            //"cols=30", "rows=5"
            final Map<String, String> params = metaField.getParams();
            assertEquals("metaField getParams().size() ", 0, params.size());                            
        }
        
        {
            final MetaField metaField = formMetaFields.get(2);

            final String propertyLabelKey = metaField.getPropertyLabelKey();
            assertEquals("metaField getPropertyLabelKey() ", "familyName", propertyLabelKey);

            final String propertyName = metaField.getPropertyName();
            assertEquals("metaField getPropertyName() ", "familyName", propertyName);

            final String propertyType = metaField.getPropertyType();
            assertEquals("metaField getPropertyType() ", "string", propertyType);

            final Class originalType = metaField.getOriginalType();
            assertEquals("metaField getOriginalType() ", String.class, originalType);

            final Class genericType = metaField.getGenericType();
            assertEquals("metaField getGenericType() ", null, genericType);

            final Annotation[] annotations = metaField.getOriginalAnnotations();                    
            assertEquals("metaField getOriginalAnnotations().length ", 0 , annotations.length);
           
            final Map<String, String> params = metaField.getParams();
            assertEquals("metaField getParams().size() ", 0, params.size());
        }
        
        {
            final MetaField metaField = formMetaFields.get(3);

            final String propertyLabelKey = metaField.getPropertyLabelKey();
            assertEquals("metaField getPropertyLabelKey() ", "smInt", propertyLabelKey);

            final String propertyName = metaField.getPropertyName();
            assertEquals("metaField getPropertyName() ", "smInt", propertyName);

            final String propertyType = metaField.getPropertyType();
            assertEquals("metaField getPropertyType() ", "number", propertyType);

            final Class originalType = metaField.getOriginalType();
            assertEquals("metaField getOriginalType() ", int.class, originalType);

            final Class genericType = metaField.getGenericType();
            assertEquals("metaField getGenericType() ", null, genericType);

            final Annotation[] annotations = metaField.getOriginalAnnotations();                    
            assertEquals("metaField getOriginalAnnotations().length ", 0 , annotations.length);

            final Map<String, String> params = metaField.getParams();
            assertEquals("metaField getParams().size() ", 0, params.size());
        }
        
        {
            final MetaField metaField = formMetaFields.get(4);

            final String propertyLabelKey = metaField.getPropertyLabelKey();
            assertEquals("metaField getPropertyLabelKey() ", "smBoolean", propertyLabelKey);

            final String propertyName = metaField.getPropertyName();
            assertEquals("metaField getPropertyName() ", "smBoolean", propertyName);

            final String propertyType = metaField.getPropertyType();
            assertEquals("metaField getPropertyType() ", "boolean", propertyType);

            final Class originalType = metaField.getOriginalType();
            assertEquals("metaField getOriginalType() ", boolean.class, originalType);

            final Class genericType = metaField.getGenericType();
            assertEquals("metaField getGenericType() ", null, genericType);

            final Annotation[] annotations = metaField.getOriginalAnnotations();                    
            assertEquals("metaField getOriginalAnnotations().length ", 0 , annotations.length);            

            final Map<String, String> params = metaField.getParams();
            assertEquals("metaField getParams().size() ", 0, params.size());
        }
        
        {
            final MetaField metaField = formMetaFields.get(5);

            final String propertyLabelKey = metaField.getPropertyLabelKey();
            assertEquals("metaField getPropertyLabelKey() ", "today", propertyLabelKey);

            final String propertyName = metaField.getPropertyName();
            assertEquals("metaField getPropertyName() ", "today", propertyName);

            final String propertyType = metaField.getPropertyType();
            assertEquals("metaField getPropertyType() ", "date", propertyType);

            final Class originalType = metaField.getOriginalType();
            assertEquals("metaField getOriginalType() ", Date.class, originalType);

            final Class genericType = metaField.getGenericType();
            assertEquals("metaField getGenericType() ", null, genericType);

            final Annotation[] annotations = metaField.getOriginalAnnotations();                    
            assertEquals("metaField getOriginalAnnotations().length ", 1 , annotations.length);
            
            final Annotation a0 = annotations[0];
            assertEquals("metaField a0.annotationType() ", Temporal.class , a0.annotationType());                       

            final Map<String, String> params = metaField.getParams();
            assertEquals("metaField getParams().size() ", 0, params.size());
        }
        
         {
            final MetaField metaField = formMetaFields.get(6);

            final String propertyLabelKey = metaField.getPropertyLabelKey();
            assertEquals("metaField getPropertyLabelKey() ", "animals", propertyLabelKey);

            final String propertyName = metaField.getPropertyName();
            assertEquals("metaField getPropertyName() ", "animals", propertyName);

            final String propertyType = metaField.getPropertyType();
            assertEquals("metaField getPropertyType() ", "collection", propertyType);

            final Class originalType = metaField.getOriginalType();
            assertEquals("metaField getOriginalType() ", List.class, originalType);

            final Class genericType = metaField.getGenericType();
            assertEquals("metaField getGenericType() ", Animal.class, genericType);

            final Annotation[] annotations = metaField.getOriginalAnnotations();                    
            assertEquals("metaField getOriginalAnnotations().length ", 1 , annotations.length); 
            
            
            final Annotation a0 = annotations[0];
            assertEquals("metaField a0.annotationType() ", OneToMany.class , a0.annotationType());

            final Map<String, String> params = metaField.getParams();
            assertEquals("metaField getParams().size() ", 0, params.size());
        }
         
          {
            final MetaField metaField = formMetaFields.get(7);

            final String propertyLabelKey = metaField.getPropertyLabelKey();
            assertEquals("metaField getPropertyLabelKey() ", "common", propertyLabelKey);

            final String propertyName = metaField.getPropertyName();
            assertEquals("metaField getPropertyName() ", "common", propertyName);

            final String propertyType = metaField.getPropertyType();
            assertEquals("metaField getPropertyType() ", "custom", propertyType);

            final Class originalType = metaField.getOriginalType();
            assertEquals("metaField getOriginalType() ", Common.class, originalType);

            final Class genericType = metaField.getGenericType();
            assertEquals("metaField getGenericType() ", null, genericType);

            final Annotation[] annotations = metaField.getOriginalAnnotations();                    
            assertEquals("metaField getOriginalAnnotations().length ", 0 , annotations.length);
                       

            final Map<String, String> params = metaField.getParams();
            assertEquals("metaField getParams().size() ", 0, params.size());
        }
          
           {
            final MetaField metaField = formMetaFields.get(8);

            final String propertyLabelKey = metaField.getPropertyLabelKey();
            assertEquals("metaField getPropertyLabelKey() ", "uploadedFile", propertyLabelKey);

            final String propertyName = metaField.getPropertyName();
            assertEquals("metaField getPropertyName() ", "uploadedFile", propertyName);

            final String propertyType = metaField.getPropertyType();
            assertEquals("metaField getPropertyType() ", "custom", propertyType);

            final Class originalType = metaField.getOriginalType();
            assertEquals("metaField getOriginalType() ", EmbeddedFile.class, originalType);

            final Class genericType = metaField.getGenericType();
            assertEquals("metaField getGenericType() ", null, genericType);

            final Annotation[] annotations = metaField.getOriginalAnnotations();                    
            assertEquals("metaField getOriginalAnnotations().length ", 0 , annotations.length);                      

            final Map<String, String> params = metaField.getParams();
            assertEquals("metaField getParams().size() ", 0, params.size());
        }

    }
}
